package com.zqxq.lottery.cms.controller;

import com.zqxq.auth.cache.UserFuncCache;
import com.zqxq.auth.entity.po.UserAdmin;
import com.zqxq.common.constant.Result;
import com.zqxq.common.enums.CodeEnum;
import com.zqxq.lottery.cms.feign.ApiOfflineFeignClient;
import com.zqxq.lottery.entity.bo.order.OfOrderBetBO;
import com.zqxq.lottery.entity.bo.user.UserPrizeBO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "商户出票管理",tags = "商户出票管理")
@RestController
@Slf4j
@RequestMapping(value = "/api", produces = "application/json")
public class ApiController {

    @Autowired
    private UserFuncCache userFuncCache;

    @Autowired
    private ApiOfflineFeignClient apiOfflineFeignClient;

    @ApiOperation(value = "线下-商户出票订单查询", notes="线下-商户出票订单查询")
    @PostMapping(value="/offline/order/page")
    public Result queryUserOrderPage(OfOrderBetBO search){
        UserAdmin userAdmin = userFuncCache.getUserAdmin(search.getToken_id());
        if(null == userAdmin)
            return new Result(CodeEnum.FAIL,"用户登录过期！");
        search.setUser(userAdmin.getPhone()+"");
        if(search.getStatus()==null)
            search.setStatus(0);
        return apiOfflineFeignClient.queryOrderPage(search);
    }

    @ApiOperation(value = "线下-商户出票", notes="线下-商户出票")
    @PostMapping(value="/offline/order/buyTicket")
    public Result buyTicket(OfOrderBetBO search){
        UserAdmin userAdmin = userFuncCache.getUserAdmin(search.getToken_id());
        if(null == userAdmin)
            return new Result(CodeEnum.FAIL,"用户登录过期！");
        search.setUser(userAdmin.getPhone()+"");
        return apiOfflineFeignClient.buyTicket(search);
    }

}
